from rest_framework import serializers

from goods.models import SKU


class CartSerializers(serializers.Serializer):
    sku_id= serializers.ImageField(lobel='商品id',min_value=1)
    count = serializers.IntegerField(label='购买数据')
    selected = serializers.BooleanField(default=True, label='商品勾选状态')

    def validate_sku_id(self, value):

        try:
            SKU.objects.get(id=value)
        except SKU.DoesNotExist:
            raise serializers.ValidationError('sku_id不存在')

        return value
